package com.iti.jets.gpts.main;



import com.iti.jets.gpts.home.AttributeTypeHome;
import com.iti.jets.gpts.home.TerminalHome;
import com.iti.jets.gpts.home.TranServiceHome;
import com.iti.jets.gpts.home.TranServiceTypeHome;
import com.iti.jets.gpts.pojo.AttributeType;
import com.iti.jets.gpts.pojo.TranService;
import com.iti.jets.gpts.pojo.TranServiceType;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author U
 */
public class ShimaaMain {

    static SessionFactory sessionFactory;
    static TranServiceHome tranServicrDAO;
    static TranServiceTypeHome tranServiceTypeDAO;
    static AttributeTypeHome attributeTypeDAO;
    private static TerminalHome terminalDAO;

    static {
        sessionFactory = new Configuration().configure()
                .buildSessionFactory();
        tranServicrDAO = new TranServiceHome(sessionFactory);
        tranServiceTypeDAO = new TranServiceTypeHome(sessionFactory);
        attributeTypeDAO = new AttributeTypeHome(sessionFactory);
        terminalDAO = new TerminalHome(sessionFactory);

    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static void setSessionFactory(SessionFactory sessionFactory) {
        ShimaaMain.sessionFactory = sessionFactory;
    }

    public static TranServiceHome getTranServicrDAO() {
        return tranServicrDAO;
    }

    public static void setTranServicrDAO(TranServiceHome tranServicrDAO) {
        ShimaaMain.tranServicrDAO = tranServicrDAO;
    }

    public static TranServiceTypeHome getTranServiceTypeDAO() {
        return tranServiceTypeDAO;
    }

    public static void setTranServiceTypeDAO(TranServiceTypeHome tranServiceTypeDAO) {
        ShimaaMain.tranServiceTypeDAO = tranServiceTypeDAO;
    }

    public static AttributeTypeHome getAttributeTypeDAO() {
        return attributeTypeDAO;
    }

    public static void setAttributeTypeDAO(AttributeTypeHome attributeTypeDAO) {
        ShimaaMain.attributeTypeDAO = attributeTypeDAO;
    }

    public static void main(String[] args) {

        TranServiceType tranServiceType1 = new TranServiceType();
        tranServiceType1.setName("Bus");
        tranServiceType1.setId(1);
        TranServiceType tranServiceType2 = new TranServiceType();
        tranServiceType2.setName("MicroBus");
        tranServiceType2.setId(2);
        //***************Insert TranserviceType in DB**********************//
//        tranServiceTypeDAO.create(tranServiceType1);
//        tranServiceTypeDAO.create(tranServiceType2);

        AttributeType attributeType1 = new AttributeType(1, "price", Boolean.TRUE);
        AttributeType attributeType2 = new AttributeType(2, "capacity", Boolean.TRUE);
        //****************Insert AttributeType in DB***********************//
//        attributeTypeDAO.create(attributeType1);
//        attributeTypeDAO.create(attributeType2);

        TranService tranService1 = new TranService();
        tranService1.setId(1);
        tranService1.setName("176");
        tranService1.setTranServiceType(tranServiceType1);
        tranService1.setTerminalByTerminal1(terminalDAO.read(1));
        tranService1.setTerminalByTerminal2(terminalDAO.read(2));
        TranService tranService2 = new TranService();
        tranService2.setId(2);
        tranService2.setName("211");
        tranService2.setTranServiceType(tranServiceType2);
        tranService2.setTerminalByTerminal1(terminalDAO.read(1));
        tranService2.setTerminalByTerminal2(terminalDAO.read(3));
        TranService tranService3 = new TranService();
        tranService3.setId(3);
        tranService3.setName("176");
        tranService3.setTranServiceType(tranServiceType1);
        tranService3.setTerminalByTerminal1(terminalDAO.read(2));
        tranService3.setTerminalByTerminal2(terminalDAO.read(3));
        //******************Insert Transervice in DB********************//
//        tranServicrDAO.create(tranService1);
//        tranServicrDAO.create(tranService2);
//        tranServicrDAO.create(tranService3);

        //***************Test Search By Name Function******************// 
        TranService service = new TranService();
        List list1 = tranServicrDAO.searchByName("211");
        for (Object c : list1) {
            service = (TranService) c;
            System.out.println(service.getTranServiceType().getName());
        }

        //***************Test Search By Terminal Function******************//
        List list2 = tranServicrDAO.searchByTerminal(terminalDAO.read(1), terminalDAO.read(3));
        for (Object c : list2) {
            service = (TranService) c;
            System.out.println(service.getTranServiceType().getName());
        }

        //********************Test  Search By Service Type Function*************//
         List list3 = tranServicrDAO.searchByServiceType(tranServiceType1);
         System.out.println(list3.isEmpty());
         for (Object c : list3) {
         service = (TranService) c;
         System.out.println(service.getName());
         }
         
        //******************Test Search By Type name Function ************************//
        List list4 = new ArrayList(tranServiceTypeDAO.searchByServiceType("Bus"));
        if (list4 == null) {
            System.out.println("No Transervice Here");
        } else {
            for (Object c : list4) {
                service = (TranService) c;
                System.out.println(service.getName());
            }
        }
    }
}
